package kaoshi.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import kaoshi.service.impl.personServiceImpl;

@WebServlet("/DelServlet")
public class DelServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        //设置响应的格式
        response.setContentType("text/html;charset=utf-8");
        //设置响应的编码格式
        response.setCharacterEncoding("utf-8");
        //获取id
        int id = Integer.parseInt(request.getParameter("id"));
        //out的
        PrintWriter out=response.getWriter();

        personServiceImpl impl=new personServiceImpl();
        int count = impl.delID(id);
        if (count>0){
            out.println("<script type=\"text/javascript\">\n" +
                    "        alert(\"删除成功！\");\n" +
                    "        location.href=\"http://localhost:8888/untitled2_war_exploded/chaxvnServlet\";\n" +
                    "    </script>");
        }else{
            out.println("<script type=\"text/javascript\">\n" +
                    "        alert(\"删除失败！\");\n" +
                    "        location.href=\"http://localhost:8888/untitled2_war_exploded/chaxvnServlet\";\n" +
                    "    </script>");
        }

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
